package com.andaily.domain.dto.thing;

import com.andaily.domain.dto.AbstractDTO;
import com.andaily.domain.dto.user.UserDto;
import com.andaily.domain.shared.DateUtils;
import com.andaily.domain.shared.security.SecurityUtils;
import com.andaily.domain.thing.*;
import com.andaily.web.context.BeanProvider;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 只有在用户登录后且数量大于0的才显示 数量信息.
 *
 * @author Shengzhao Li
 */
public class ThingAmountDto extends AbstractDTO {

    //事件的数量
    private int eventAmount;
    //预警的数量, 是指事情开始时间在现在之前且状态还是CREATED
    private int warningAmount;
    //历史的数量, 指状态为END或者CANCEL的事情
    private int historyAmount;
    //监控的数量, 指状态为PENDING的事情
    private int monitoringAmount;

    public ThingAmountDto() {
    }

    public void setEventAmount(int eventAmount) {
        this.eventAmount = eventAmount;
    }

    public void setWarningAmount(int warningAmount) {
        this.warningAmount = warningAmount;
    }

    public void setHistoryAmount(int historyAmount) {
        this.historyAmount = historyAmount;
    }

    public void setMonitoringAmount(int monitoringAmount) {
        this.monitoringAmount = monitoringAmount;
    }

    public int getEventAmount() {
        return eventAmount;
    }

    private boolean showIt(int amount) {
        return (SecurityUtils.isLogged() && amount > 0);
    }

    public String getEventAmountHtml() {
        StringBuilder sb = new StringBuilder();
        if (showIt(eventAmount)) {
            sb.append("(").append(eventAmount).append(")");
        }
        return sb.toString();
    }

    public String getWarningAmountHtml() {
        StringBuilder sb = new StringBuilder();
        if (showIt(warningAmount)) {
            sb.append("(").append(warningAmount).append(")");
        }
        return sb.toString();
    }

    public String getHistoryAmountHtml() {
        StringBuilder sb = new StringBuilder();
        if (showIt(historyAmount)) {
            sb.append("(").append(historyAmount).append(")");
        }
        return sb.toString();
    }

    public String getMonitoringAmountHtml() {
        StringBuilder sb = new StringBuilder();
        if (showIt(monitoringAmount)) {
            sb.append("(").append(monitoringAmount).append(")");
        }
        return sb.toString();
    }

    public int getWarningAmount() {
        return warningAmount;
    }

    public int getHistoryAmount() {
        return historyAmount;
    }

    public int getMonitoringAmount() {
        return monitoringAmount;
    }
}
